package com.lanchetech.admin.controller;

import com.lanchetech.admin.aop.OperatorLog;
import com.lanchetech.admin.service.WebService;
import com.lanchetech.bean.request.PageReq;
import com.lanchetech.bean.response.BasePageResp;
import com.lanchetech.bean.response.BaseResp;
import com.lanchetech.bean.response.ResultData;
import com.lanchetech.bean.vo.AdminHomeStatisticsVO;
import com.lanchetech.bean.vo.CustomPageEditVO;
import com.lanchetech.bean.vo.OnePostVO;
import com.lanchetech.entity.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "网站管理接口", tags = "网站管理接口")
@RequestMapping("/api/web")
@RestController
public class WebController {
    @Autowired
    WebService webService;

    @ApiOperation("获取所有网站配置接口")
    @PreAuthorize("hasAuthority('web.index')")
    @GetMapping("/getAllWebConfig")
    public ResultData<List<WebConfig>> getAllWebConfig() {
        return webService.getAllWebConfig();
    }

    @OperatorLog("修改指定网站配置")
    @ApiOperation("修改指定网站配置")
    @PreAuthorize("hasAuthority('web.index.edit.auth')")
    @PostMapping("/modifyWebConfig")
    public BaseResp modifyWebConfig(@RequestBody WebConfig webConfig) {
        return webService.modifyWebConfig(webConfig);
    }

    @ApiOperation("获取所有嗨跑分销配置")
    @PreAuthorize("hasAuthority('web.hipo-config')")
    @GetMapping("/getHipoConfigList")
    public ResultData<List<HipoConfig>> getHipoConfigList() {
        return webService.getHipoConfigList();
    }

    @OperatorLog("修改指定嗨跑分销配置")
    @ApiOperation("修改指定嗨跑分销配置")
    @PreAuthorize("hasAuthority('web.hipo-config.edit.auth')")
    @PostMapping("/modifyHipoConfig")
    public BaseResp modifyHipoConfig(@RequestBody HipoConfig req) {
        return webService.modifyHipoConfig(req);
    }

    @ApiOperation("获取首页统计")
    @PreAuthorize("hasAuthority('home.index')")
    @GetMapping("/getHomeStatistics")
    public ResultData<AdminHomeStatisticsVO> getHomeStatistics() {
        return webService.getHomeStatistics();
    }

    @OperatorLog("编辑轮播图海报图")
    @ApiOperation("编辑轮播图海报图")
    @PreAuthorize("hasAuthority('web.banner-index.edit.auth')")
    @PostMapping("/editBanner")
    public BaseResp editBanner(@RequestBody Banner banner) {
        return webService.editBanner(banner);
    }

    @ApiOperation("获取轮播图海报图分页")
    @PreAuthorize("hasAuthority('web.banner-index')")
    @PostMapping("/getBannerPage")
    public ResultData<BasePageResp<Banner>> getBannerPage(@RequestBody PageReq req) {
        return webService.getBannerPage(req);
    }

    @ApiOperation("获取轮播图海报图详情")
    @PreAuthorize("hasAuthority('web.banner-edit')")
    @GetMapping("/getBannerDetail")
    public ResultData<Banner> getBannerDetail(@RequestParam("id") Long id) {
        return webService.getBannerDetail(id);
    }

    @OperatorLog("删除轮播图海报图")
    @ApiOperation("删除轮播图海报图")
    @PreAuthorize("hasAuthority('web.banner-index.delete.auth')")
    @GetMapping("/deleteBanner")
    public BaseResp deleteBanner(@RequestParam("id") Long id) {
        return webService.deleteBanner(id);
    }

    @OperatorLog("编辑导航菜单")
    @ApiOperation("编辑导航菜单")
    @PreAuthorize("hasAuthority('web.navigation-index.edit.auth')")
    @PostMapping("/editNavigation")
    public BaseResp editNavigation(@RequestBody Navigation navigation) {
        return webService.editNavigation(navigation);
    }

    @ApiOperation("获取导航菜单分页")
    @PreAuthorize("hasAuthority('web.navigation-index')")
    @PostMapping("/getNavigationPage")
    public ResultData<BasePageResp<Navigation>> getNavigationPage(@RequestBody PageReq req) {
        return webService.getNavigationPage(req);
    }

    @ApiOperation("获取导航菜单详情")
    @PreAuthorize("hasAuthority('web.navigation-edit')")
    @GetMapping("/getNavigationDetail")
    public ResultData<Navigation> getNavigationDetail(@RequestParam("id") Long id) {
        return webService.getNavigationDetail(id);
    }

    @OperatorLog("删除导航菜单")
    @ApiOperation("删除导航菜单")
    @PreAuthorize("hasAuthority('web.navigation-index.delete.auth')")
    @GetMapping("/deleteNavigation")
    public BaseResp deleteNavigation(@RequestParam("id") Long id) {
        return webService.deleteNavigation(id);
    }


    @ApiOperation(value = "获取广告弹窗分页")
    @PreAuthorize("hasAuthority('web.advertisement-index')")
    @PostMapping("/getAdvertisementPage")
    public ResultData<BasePageResp<Advertisement>> getAdvertisementPage(@RequestBody PageReq req) {
        return webService.getAdvertisementPage(req);
    }

    @ApiOperation(value = "获取广告弹窗详情")
    @PreAuthorize("hasAuthority('web.advertisement-index.edit.auth')")
    @GetMapping("/getAdvertisementDetail")
    public ResultData<Advertisement> getAdvertisementDetail(@RequestParam("id") Long id) {
        return webService.getAdvertisementDetail(id);
    }

    @OperatorLog("删除广告弹窗")
    @ApiOperation(value = "删除广告弹窗")
    @PreAuthorize("hasAuthority('web.advertisement-index.edit.auth')")
    @GetMapping("/deleteAdvertisement")
    public BaseResp deleteAdvertisement(@RequestParam("id") Long id) {
        return webService.deleteAdvertisement(id);
    }

    @OperatorLog("编辑广告弹窗")
    @ApiOperation(value = "编辑广告弹窗")
    @PreAuthorize("hasAuthority('web.advertisement-index.edit.auth')")
    @PostMapping("/editAdvertisement")
    public BaseResp editAdvertisement(@RequestBody Advertisement advertisement) {
        return webService.editAdvertisement(advertisement);
    }

    @OperatorLog("编辑自定义专题")
    @ApiOperation(value = "编辑自定义专题")
    @PreAuthorize("hasAuthority('web.custom-page.edit.auth')")
    @PostMapping("/editCustomPage")
    public BaseResp editCustomPage(@RequestBody CustomPageEditVO req) {
        return webService.editCustomPage(req);
    }

    @ApiOperation(value = "获取自定义专题详情")
    @GetMapping("/getCustomPageDetail")
    public ResultData<CustomPageEditVO> getCustomPageDetail(@RequestParam("id") Long id) {
        return webService.getCustomPageDetail(id);
    }

    @ApiOperation(value = "删除自定义专题")
    @PreAuthorize("hasAuthority('web.custom-page.edit.auth')")
    @GetMapping("/deleteCustomPage")
    public BaseResp deleteCustomPage(@RequestParam("id") Long id) {
        return webService.deleteCustomPage(id);
    }

    @ApiOperation(value = "获取自定义专题分页")
    @PreAuthorize("hasAuthority('web.custom-page')")
    @PostMapping("/getCustomPage")
    public ResultData<BasePageResp<CustomPage>> getCustomPage(@RequestBody PageReq req) {
        return webService.getCustomPage(req);
    }

    @OperatorLog("编辑推广海报")
    @ApiOperation("编辑推广海报")
    @PreAuthorize("hasAuthority('web.poster.edit.auth')")
    @PostMapping("/editPoster")
    public BaseResp editPoster(@RequestBody Poster poster) {
        return webService.editPoster(poster);
    }

    @ApiOperation("获取推广海报分页")
    @PreAuthorize("hasAuthority('web.poster')")
    @PostMapping("/getPosterPage")
    public ResultData<BasePageResp<Poster>> getPosterPage(@RequestBody PageReq req) {
        return webService.getPosterPage(req);
    }

    @ApiOperation("获取推广海报详情")
    @PreAuthorize("hasAuthority('web.poster')")
    @GetMapping("/getPosterDetail")
    public ResultData<Poster> getPosterDetail(@RequestParam("id") Long id) {
        return webService.getPosterDetail(id);
    }

    @OperatorLog("删除推广海报")
    @ApiOperation("删除推广海报")
    @PreAuthorize("hasAuthority('web.poster.edit.auth')")
    @GetMapping("/deletePoster")
    public BaseResp deletePoster(@RequestParam("id") Long id) {
        return webService.deletePoster(id);
    }

    @OperatorLog("编辑一键发圈")
    @ApiOperation("编辑一键发圈")
    @PreAuthorize("hasAuthority('web.one-post.edit.auth')")
    @PostMapping("/editOnePost")
    public BaseResp editOnePost(@RequestBody OnePost onePost) {
        return webService.editOnePost(onePost);
    }

    @ApiOperation("获取一键发圈分页")
    @PreAuthorize("hasAuthority('web.one-post')")
    @PostMapping("/getOnePostPage")
    public ResultData<BasePageResp<OnePost>> getOnePostPage(@RequestBody PageReq req) {
        return webService.getOnePostPage(req);
    }

    @ApiOperation("获取一键发圈详情")
    @PreAuthorize("hasAuthority('web.one-post')")
    @GetMapping("/getOnePostDetail")
    public ResultData<OnePostVO> getOnePostDetail(@RequestParam("id") Long id) {
        return webService.getOnePostDetail(id);
    }

    @OperatorLog("删除一键发圈")
    @ApiOperation("删除一键发圈")
    @PreAuthorize("hasAuthority('web.one-post.edit.auth')")
    @GetMapping("/deleteOnePost")
    public BaseResp deleteOnePost(@RequestParam("id") Long id) {
        return webService.deleteOnePost(id);
    }
}
